#include "Painter.h"

/**
 * 
 * @param filename
 * @param width
 * @param height
 */
Painter::Painter(const char * filename, unsigned set_width, unsigned set_height)
{
    stream.open(filename, std::ios::out);
    width = set_width;
    height = set_height;
    
    stream  << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl
            << "<svg version = \"1.1\" "
            << "baseProfile=\"full\" "
            << "xmlns = \"http://www.w3.org/2000/svg\" "
            << "xmlns:xlink = \"http://www.w3.org/1999/xlink\" "
            << "xmlns:ev = \"http://www.w3.org/2001/xml-events\" "
            << "height = \"" << height << "px\"  width = \"" << width << "px\">" << std::endl;
}

/**
 * 
 * @param sourse
 * @param dest
 * @param color
 */
void Painter::drawLine(Dot sourse, Dot dest, Color color)
{
    stream << "<line x1=\"" << sourse.getX() << "\" y1=\"" << (height - sourse.getY()) << "\" x2=\"" << dest.getX() << "\" y2=\"" << (height - dest.getY()) << "\" "
           << "style=\"stroke-width:1;\" stroke=\"rgb(" << color.getRed() << "," << color.getGreen() << "," << color.getBlue() << ")\" />" << std::endl;
}

/**
 * 
 * @param center
 * @param radius
 * @param border_color
 */
void Painter::drawCircle(Dot center, unsigned radius, Color border_color)
{
    stream << "<circle cx=\"" << center.getX() << "\" cy=\"" << (height-center.getY()) << "\" r=\"" << radius << "\" fill=\"none\" "
           << "stroke=\"rgb(" << border_color.getRed() << "," << border_color.getGreen() << "," << border_color.getBlue() << ")\" stroke-width=\"1\" />" << std::endl;
}

/**
 * 
 */
void Painter::finish()
{
    stream << "</svg>" << std::endl;
    stream.close();
}
